#include <stdio.h> 
#include <omp.h>
void calc_val(float *val){
	*val *=2;
}

void boxster(float *box_totals, float *vals, int *box, int N)
{
	#pragma omp parallel for
	for(int idx=0; idx<=N; idx++)
	{
		calc_val(&vals[idx]);
		#pragma omp atomic hint(omp_sync_hint_uncontended)
		box_totals[ box[idx] ] = box_totals[ box[idx] ]+ vals[idx];
	}
}

int main(){
	float box_totals[5]={0.0};
	float vals[6] = {1.0,2.0,3.0,4.0,5.0,6.0};
	int box[6] = {0,1,2,1,0,2};
	int N=5;
	boxster(box_totals, vals, box, N);
	for (int i=0;i<5;i++){
		printf("box_totals[%d] = %f\n", i, box_totals[i]);
	}
	
	return 0;
}


